package com.example.jqying.androiddemo.jump;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.jqying.androiddemo.R;

/**
 * Created by apple on 2018/6/22.
 * 这是一个Activity之间互相跳转的例子
 * AActivity跳转到BActivity startActivityForResult ，在BActivity finish()时setResult传递参数回来
 * 也可以只是简单的跳转，不传递参数
 */

public class AActivity extends AppCompatActivity {

    private final String TAG = ">>>>>>AActivity<<<<<<";
    private Button mJump;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.i(TAG,"onActivityResult");
        Toast.makeText(AActivity.this,data.getExtras().getString("tip"),Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG,"onCreate");
        setContentView(R.layout.activity_a);

        /*
        显示调用 1
         */
        mJump = (Button) findViewById(R.id.btn_jump);
        mJump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                /*
                显示调用 1
                 */
                Intent intent = new Intent(AActivity.this,BActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("name","jqying");
                bundle.putInt("number",666);
                intent.putExtras(bundle);
                //startActivity(intent);
                startActivityForResult(intent,0); //获取BActivity在finish通过bundle时传递回来的参数，通过onActivityResult函数
                /*
                显示调用 2
                 */
//                Intent intent = new Intent();
//                intent.setClass(AActivity.this,BActivity.class);
//                startActivity(intent);
                /*
                显示调用 3
                 */
//                Intent intent = new Intent();
//                intent.setClassName(AActivity.this,"com.example.jqying.androiddemo.jump.BActivity");
//                startActivity(intent);

                /*
                显示调用 4
                 */
//                Intent intent = new Intent();
//                intent.setComponent(new ComponentName(AActivity.this,"com.example.jqying.androiddemo.jump.BActivity"));
//                startActivity(intent);

                /*
                显示调用 1
                 */
//                Intent intent = new Intent();
//                intent.setAction("android.intent.action.BActivity");
//                startActivity(intent);


            }
        });



    }
}
